import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // api
        api: 'http://localhost:9800',

        /**
         * 用户信息
         */
        userData: {
            /*"userId": 32,
            "userName": "w五",
            "password": "wwwwww",
            // 0用户 1工作人员 2管理员
            "role": "2",
            "address": null,
            "birthday": null,
            "phone": "12312312312",
            "info": "123456789123416789",
            "img": "http://localhost:9800/1619272005514_226.png",
            "workPlace": null,
            "tuserName": "王五"*/
        },

        // 把用户数据以id为健存为对象
        userObjectData: null,

        /**
         * 表单校验
         */
        formRule: {
            phone: [
                {required: true, message: '请输入手机号', trigger: 'blur'},
                {pattern: /^1[0-9]{10}$/, message: '手机号输入错误', trigger: 'blur'}
            ],
            password: [
                {required: true, message: '请输入密码', trigger: 'blur'},
                {min: 6, max: 18, message: '密码长度在6到18个字符', trigger: 'blur'}
            ],
            // 真名
            name: [
                {required: true, message: '请输入姓名', trigger: 'blur'},
                {pattern: /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/, message: '姓名输入错误', trigger: 'blur'}
            ],
            userName: [
                {required: true, message: '请输入昵称', trigger: 'blur'},
                {min: 1, max: 12, message: '昵称长度在1到12个字符', trigger: 'blur'}
            ],
            idCard: [
                {required: true, message: '请输入身份证号', trigger: 'blur'},
                {pattern: /^[0-9]{18}$/, message: '身份证号输入错误', trigger: 'blur'}
            ]
        }
    },
    mutations: {
        /**
         * 设置用户信息
         *
         * @param state
         * @param data
         */
        setUserData(state, data) {
            state.userData = data;
        },

        /**
         * 把用户数据以id为健存为对象
         *
         * @param state
         * @param data
         */
        setUserObjectData(state, data) {
            state.userObjectData = data;
        }

    },
    actions: {},
    modules: {}
})
